package com.lk.ii.controller;

import java.util.List;

import com.lk.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lk.common.annotation.Log;
import com.lk.common.enums.BusinessType;
import com.lk.ii.domain.IiProduct;
import com.lk.ii.service.IIiProductService;
import com.lk.common.core.controller.BaseController;
import com.lk.common.core.domain.AjaxResult;
import com.lk.common.utils.poi.ExcelUtil;
import com.lk.common.core.page.TableDataInfo;

/**
 * 产品服务Controller
 * 
 * @author lk
 * @date 2021-02-22
 */
@Controller
@RequestMapping("/ii/product")
public class IiProductController extends BaseController
{
    private String prefix = "ii/product";

    @Autowired
    private IIiProductService iiProductService;

    @RequiresPermissions("ii:product:view")
    @GetMapping()
    public String product()
    {
        return prefix + "/product";
    }

    /**
     * 查询产品服务列表
     */
    @RequiresPermissions("ii:product:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IiProduct iiProduct)
    {
        startPage();
        List<IiProduct> list = iiProductService.selectIiProductList(iiProduct);
        return getDataTable(list);
    }

    /**
     * 导出产品服务列表
     */
    @RequiresPermissions("ii:product:export")
    @Log(title = "产品服务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IiProduct iiProduct)
    {
        List<IiProduct> list = iiProductService.selectIiProductList(iiProduct);
        ExcelUtil<IiProduct> util = new ExcelUtil<IiProduct>(IiProduct.class);
        return util.exportExcel(list, "product");
    }

    /**
     * 新增产品服务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存产品服务
     */
    @RequiresPermissions("ii:product:add")
    @Log(title = "产品服务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IiProduct iiProduct)
    {
        iiProduct.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(iiProductService.insertIiProduct(iiProduct));
    }

    /**
     * 修改产品服务
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IiProduct iiProduct = iiProductService.selectIiProductById(id);
        mmap.put("iiProduct", iiProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品服务
     */
    @RequiresPermissions("ii:product:edit")
    @Log(title = "产品服务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IiProduct iiProduct)
    {
        iiProduct.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(iiProductService.updateIiProduct(iiProduct));
    }

    /**
     * 删除产品服务
     */
    @RequiresPermissions("ii:product:remove")
    @Log(title = "产品服务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iiProductService.deleteIiProductByIds(ids));
    }
}
